home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
ARGONET
/
PD
/
MATHS
/
RLAB
/
RLAB125.ZIP
/
!RLaB
/
toolbox
/
trapz
< prev
next >
Wrap
Text File
|
1995-03-20
|
739b
|
31 lines
//
// a = trapz(y,x)
//
// find the area under the curve y = f(x) using the trapezoidal rule
//
// x = vector containing the independent variable data points
// the elements of x need not be equally spaced
// y = f(x) = vector of the function values corresponding to the
// elements in x
//
// a = the area under f(x) in the interval defined by x
//
// Written by: Duane Hanselman, University of Maine, (207)-581-2246
trapz = function (y, x)
{
local (x, y)
x = x[:]'; // make sure x and y are row vectors
y = y[:]';
ly = length(y);
lx = length(x);
if (lx != ly) {
error(" x and y must be the same length");
}
a = 0.5*([0, y] + [y, 0]) .* ([x, 0] - [0, x]);
a = sum (a[1;2:ly]);
return a;
};